package com.sgb.packers.api;

import com.sgb.link.api.ErrorInterceptor;
import com.sgb.net.BuildConfig;
import com.sgb.net.core.BaseCompatibleNet;
import com.sgb.net.core.UrlInterceptor;
import com.swgk.core.base.model.factory.PCCookieInterceptor;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

/**
 * Time:2021/6/16
 * Author:黄淋
 * Description:
 */
public class PackersNet extends BaseCompatibleNet {

    private final PackersService merchantsService;

    private PackersNet() {
        merchantsService = getService(PackersService.class, BuildConfig.BASE_URL);
    }

    private static class Single {
        private static final PackersNet instance = new PackersNet();
    }

    public static PackersNet getInstance() {
        return Single.instance;
    }

    @Override
    public void initNet() {
        //todo  更换接口前暂用老配置
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        //通用配置
        builder.addInterceptor(new UrlInterceptor(1))
                .addInterceptor(new PCCookieInterceptor())
                .addInterceptor(new ErrorInterceptor())
                .readTimeout(10, TimeUnit.SECONDS)
                .writeTimeout(10, TimeUnit.SECONDS)
                .connectTimeout(10, TimeUnit.SECONDS);
        handleBuilder(builder);
        mClient = builder.build();
    }

    @Override
    protected void handleBuilder(OkHttpClient.Builder builder) {

    }

    public PackersService getService() {
        return merchantsService;
    }
}
